package org.noootsab.gae.games.tzaar.model.stat {
import com.adobe.serialization.json.JSON;

import flash.utils.IDataInput;
import flash.utils.IDataOutput;
import flash.utils.IExternalizable;

import mx.collections.ArrayCollection;
import mx.logging.ILogger;
import mx.logging.Log;

import org.noootsab.gae.games.tzaar.model.player.Player;

[Bindable]
[RemoteClass(alias="org.noootsab.gae.games.tzaar.model.Statistic")]
public class Statistic implements IExternalizable {
    private static var LOG:ILogger = Log.getLogger("org.noootsab.gae.games.tzaar.model.stat.Statistic");

    public var key:String;
    public var player:String;
    public var won:uint;
    public var lost:uint;
    public var scores:ArrayCollection;

    public function Statistic() {
        super();
    }

    public function readExternal(input:IDataInput):void {
        key = input.readObject() as String;
        player = input.readObject() as String;
        won = input.readObject();
        lost = input.readObject();
        var ro:Object = input.readObject();
        ro = JSON.decode(ro as String);
        if (ro is Array) {
            scores = new ArrayCollection(ro as Array);
        } else if (ro is Object) {
            scores = new ArrayCollection();
        } else if (ro is ArrayCollection) {
            scores = ro as ArrayCollection;
        }
    }

    public function writeExternal(output:IDataOutput):void {
        //should never be called
    }
}
}